<?php

namespace Biz\model\SuperSubsidy;

use Doraemon\pockets\datebase\BaseDbModel;

/**
 * 订单信息
 */
class YouZanOrderInfo extends BaseDbModel
{
    const _CONFIG_FILE_ = 'db_store';

    const _CONFIG_SELECT_ = 'db_brand_activity';

    const _DATABASE_ = 'brand_activity';

    const _TABLE_NAME = 'youzan_order_info';

    const RECEIVER_TEL_SECRETS = '4b42dac72db4deded329daa5230194bf';

    //主订单状态
    const STATUS_WAIT_BUYER_PAY = 'WAIT_BUYER_PAY';//（等待买家付款，定金预售描述：定金待付、等待尾款支付开始、尾款待付）
    const STATUS_TRADE_PAID = 'TRADE_PAID';//订单已支付 PS：TRADE_PAID状态仅代表当前订单已支付成功，表示瞬时状态，稍后会自动修改成后面的状态。如果不关心此状态请再次请求详情接口获取下一个状态。
    const STATUS_WAIT_CONFIRM = 'WAIT_CONFIRM';//（待确认，包含待成团、待接单等等。即：买家已付款，等待成团或等待接单）
    const STATUS_WAIT_SELLER_SEND_GOODS = 'WAIT_SELLER_SEND_GOODS';//（等待卖家发货，即：买家已付款）
    const STATUS_WAIT_BUYER_CONFIRM_GOODS = 'WAIT_BUYER_CONFIRM_GOODS';// (等待买家确认收货，即：卖家已发货)
    const STATUS_TRADE_SUCCESS = 'TRADE_SUCCESS';//（买家已签收以及订单成功）
    const STATUS_TRADE_CLOSED = 'TRADE_CLOSED';//（交易关闭）

    public static function getByWhere($where, $field = '*')
    {
        return self::get($field, $where);
    }

    public static function selectByWhere($where, $select = '*')
    {
        $list = self::select($select, $where);

        return $list;
    }

    public static function selectCountWhere($where)
    {
        $count = self::count('id', $where);

        return $count;
    }


    public static function insertData($data)
    {
        if (!isset($data['created_at'])) {
            $data['created_at'] = date('Y-m-d H:i:s');
        }
        if (!isset($data['update_at'])) {
            $data['update_at'] = date('Y-m-d H:i:s');
        }
        $ret = self::insert($data);
        if ($ret->errorCode() !== '00000') {
            return false;
        }

        return self::id();
    }


    public static function updateData($data, $where)
    {
        if (!isset($data['update_at'])) {
            $data['update_at'] = date('Y-m-d H:i:s');
        }
        $ret = self::update($data, $where);
        if ($ret->errorCode() !== '00000') {
            return false;
        }

        return true;
    }
}